﻿using System;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace Mvc.Validation.Validators
{
    class StringLengthValidator : ValueValidator
    {
        public StringLengthValidator()
			: this(null)
		{ }

        public StringLengthValidator(string messageTemplate)
			: base(messageTemplate, null, false)
		{ }

		protected void DoValidate(object objectToValidate,
			object currentTarget,
			string key,
			ValidationResults validationResults,int MaxLength)
        {
            var stringValue = //(string)
                objectToValidate.ToString();
            if (stringValue.Length > MaxLength)
			{
				LogValidationResult(validationResults, GetMessage(objectToValidate, key), currentTarget, key);
                return;
			}
		}

        protected override string DefaultNonNegatedMessageTemplate
        {
            get { return "Element length must be less"; }
        }

        protected override string DefaultNegatedMessageTemplate
        {
            get { return null; }
        }

        protected override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            throw new NotImplementedException();
        }
    }
}
